{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.DotNet.Interactive.SqlServer, 1.0.0-beta.22227.1</span></li></ul></div></div>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "Loading extensions from `Microsoft.DotNet.Interactive.SqlServer.dll`"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/html": [
              "<details><summary>Query Microsoft SQL Server databases.</summary>\r\n",
              "    <p>This extension adds support for connecting to Microsoft SQL Server databases using the <code>#!connect mssql</code> magic command. For more information, run a cell using the <code>#!sql</code> magic command.</p>\r\n",
              "    </details>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "#r \"nuget: Microsoft.DotNet.Interactive.SqlServer, *-*\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [],
      "source": [
        "var connectionString = Environment.GetEnvironmentVariable(\"TEST_MSSQL_CONNECTION_STRING\");"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Kernel added: #!sql-adventureworks"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "#!connect mssql --kernel-name adventureworks @csharp:connectionString "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [],
      "source": [
        "#!value --name country_region_code --from-value @input:country_region_code"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Adding shared variable declaration statement : DECLARE @territory_name NVarChar(2) = N'US';"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Adding shared variable declaration statement : DECLARE @country_region_code NVarChar(2) = N'US';"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "(8 rows affected)"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/csv": [
              "BusinessEntityID,TerritoryID,SalesQuota,Bonus,CommissionPct,SalesYTD,SalesLastYear,rowguid,ModifiedDate,TerritoryID (2),Name,CountryRegionCode,Group,SalesYTD (2),SalesLastYear (2),CostYTD,CostLastYear,rowguid (2),ModifiedDate (2)\r\n",
              "275,2,300000.0000,4100.0000,0.0120,3763178.1787,1750406.4785,1e0a7274-3064-4f58-88ee-4c6586c87169,2011-05-24T00:00:00.0000000,2,Northeast,US,North America,2402176.8476,3607148.9371,0.0000,0.0000,00fb7309-96cc-49e2-8363-0a1ba72486f2,2008-04-30T00:00:00.0000000\r\n",
              "276,4,250000.0000,2000.0000,0.0150,4251368.5497,1439156.0291,4dd9eee4-8e81-4f8c-af97-683394c1f7c0,2011-05-24T00:00:00.0000000,4,Southwest,US,North America,10510853.8739,5366575.7098,0.0000,0.0000,dc3e9ea0-7950-4431-9428-99dbcbc33865,2008-04-30T00:00:00.0000000\r\n",
              "277,3,250000.0000,2500.0000,0.0150,3189418.3662,1997186.2037,39012928-bfec-4242-874d-423162c3f567,2011-05-24T00:00:00.0000000,3,Central,US,North America,3072175.1180,3205014.0767,0.0000,0.0000,df6e7fd8-1a8d-468c-b103-ed8addb452c1,2008-04-30T00:00:00.0000000\r\n",
              "279,5,300000.0000,6700.0000,0.0100,2315185.6110,1849640.9418,52a5179d-3239-4157-ae29-17e868296dc0,2011-05-24T00:00:00.0000000,5,Southeast,US,North America,2538667.2515,3925071.4318,0.0000,0.0000,6dc4165a-5e4c-42d2-809d-4344e0ac75e7,2008-04-30T00:00:00.0000000\r\n",
              "280,1,250000.0000,5000.0000,0.0100,1352577.1325,1927059.1780,be941a4a-fb50-4947-bda4-bb8972365b08,2011-05-24T00:00:00.0000000,1,Northwest,US,North America,7887186.7882,3298694.4938,0.0000,0.0000,43689a10-e30b-497f-b0de-11de20267ff7,2008-04-30T00:00:00.0000000\r\n",
              "281,4,250000.0000,3550.0000,0.0100,2458535.6169,2073505.9999,35326ddb-7278-4fef-b3ba-ea137b69094e,2011-05-24T00:00:00.0000000,4,Southwest,US,North America,10510853.8739,5366575.7098,0.0000,0.0000,dc3e9ea0-7950-4431-9428-99dbcbc33865,2008-04-30T00:00:00.0000000\r\n",
              "283,1,250000.0000,3500.0000,0.0120,1573012.9383,1371635.3158,6bac15b2-8ffb-45a9-b6d5-040e16c2073f,2011-05-24T00:00:00.0000000,1,Northwest,US,North America,7887186.7882,3298694.4938,0.0000,0.0000,43689a10-e30b-497f-b0de-11de20267ff7,2008-04-30T00:00:00.0000000\r\n",
              "284,1,300000.0000,3900.0000,0.0190,1576562.1966,0.0000,ac94ec04-a2dc-43e3-8654-dd0c546abc17,2012-09-23T00:00:00.0000000,1,Northwest,US,North America,7887186.7882,3298694.4938,0.0000,0.0000,43689a10-e30b-497f-b0de-11de20267ff7,2008-04-30T00:00:00.0000000\r\n"
            ],
            "text/html": [
              "<table><thead><tr><td><span>BusinessEntityID</span></td><td><span>TerritoryID</span></td><td><span>SalesQuota</span></td><td><span>Bonus</span></td><td><span>CommissionPct</span></td><td><span>SalesYTD</span></td><td><span>SalesLastYear</span></td><td><span>rowguid</span></td><td><span>ModifiedDate</span></td><td><span>TerritoryID (2)</span></td><td><span>Name</span></td><td><span>CountryRegionCode</span></td><td><span>Group</span></td><td><span>SalesYTD (2)</span></td><td><span>SalesLastYear (2)</span></td><td><span>CostYTD</span></td><td><span>CostLastYear</span></td><td><span>rowguid (2)</span></td><td><span>ModifiedDate (2)</span></td></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">275</div></td><td><div class=\"dni-plaintext\">2</div></td><td><div class=\"dni-plaintext\">300000.0000</div></td><td><div class=\"dni-plaintext\">4100.0000</div></td><td><div class=\"dni-plaintext\">0.0120</div></td><td><div class=\"dni-plaintext\">3763178.1787</div></td><td><div class=\"dni-plaintext\">1750406.4785</div></td><td><div class=\"dni-plaintext\">1e0a7274-3064-4f58-88ee-4c6586c87169</div></td><td><span>2011-05-24 00:00:00Z</span></td><td><div class=\"dni-plaintext\">2</div></td><td>Northeast</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">2402176.8476</div></td><td><div class=\"dni-plaintext\">3607148.9371</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">00fb7309-96cc-49e2-8363-0a1ba72486f2</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr><tr><td><div class=\"dni-plaintext\">276</div></td><td><div class=\"dni-plaintext\">4</div></td><td><div class=\"dni-plaintext\">250000.0000</div></td><td><div class=\"dni-plaintext\">2000.0000</div></td><td><div class=\"dni-plaintext\">0.0150</div></td><td><div class=\"dni-plaintext\">4251368.5497</div></td><td><div class=\"dni-plaintext\">1439156.0291</div></td><td><div class=\"dni-plaintext\">4dd9eee4-8e81-4f8c-af97-683394c1f7c0</div></td><td><span>2011-05-24 00:00:00Z</span></td><td><div class=\"dni-plaintext\">4</div></td><td>Southwest</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">10510853.8739</div></td><td><div class=\"dni-plaintext\">5366575.7098</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">dc3e9ea0-7950-4431-9428-99dbcbc33865</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr><tr><td><div class=\"dni-plaintext\">277</div></td><td><div class=\"dni-plaintext\">3</div></td><td><div class=\"dni-plaintext\">250000.0000</div></td><td><div class=\"dni-plaintext\">2500.0000</div></td><td><div class=\"dni-plaintext\">0.0150</div></td><td><div class=\"dni-plaintext\">3189418.3662</div></td><td><div class=\"dni-plaintext\">1997186.2037</div></td><td><div class=\"dni-plaintext\">39012928-bfec-4242-874d-423162c3f567</div></td><td><span>2011-05-24 00:00:00Z</span></td><td><div class=\"dni-plaintext\">3</div></td><td>Central</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">3072175.1180</div></td><td><div class=\"dni-plaintext\">3205014.0767</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">df6e7fd8-1a8d-468c-b103-ed8addb452c1</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr><tr><td><div class=\"dni-plaintext\">279</div></td><td><div class=\"dni-plaintext\">5</div></td><td><div class=\"dni-plaintext\">300000.0000</div></td><td><div class=\"dni-plaintext\">6700.0000</div></td><td><div class=\"dni-plaintext\">0.0100</div></td><td><div class=\"dni-plaintext\">2315185.6110</div></td><td><div class=\"dni-plaintext\">1849640.9418</div></td><td><div class=\"dni-plaintext\">52a5179d-3239-4157-ae29-17e868296dc0</div></td><td><span>2011-05-24 00:00:00Z</span></td><td><div class=\"dni-plaintext\">5</div></td><td>Southeast</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">2538667.2515</div></td><td><div class=\"dni-plaintext\">3925071.4318</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">6dc4165a-5e4c-42d2-809d-4344e0ac75e7</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr><tr><td><div class=\"dni-plaintext\">280</div></td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">250000.0000</div></td><td><div class=\"dni-plaintext\">5000.0000</div></td><td><div class=\"dni-plaintext\">0.0100</div></td><td><div class=\"dni-plaintext\">1352577.1325</div></td><td><div class=\"dni-plaintext\">1927059.1780</div></td><td><div class=\"dni-plaintext\">be941a4a-fb50-4947-bda4-bb8972365b08</div></td><td><span>2011-05-24 00:00:00Z</span></td><td><div class=\"dni-plaintext\">1</div></td><td>Northwest</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">7887186.7882</div></td><td><div class=\"dni-plaintext\">3298694.4938</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">43689a10-e30b-497f-b0de-11de20267ff7</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr><tr><td><div class=\"dni-plaintext\">281</div></td><td><div class=\"dni-plaintext\">4</div></td><td><div class=\"dni-plaintext\">250000.0000</div></td><td><div class=\"dni-plaintext\">3550.0000</div></td><td><div class=\"dni-plaintext\">0.0100</div></td><td><div class=\"dni-plaintext\">2458535.6169</div></td><td><div class=\"dni-plaintext\">2073505.9999</div></td><td><div class=\"dni-plaintext\">35326ddb-7278-4fef-b3ba-ea137b69094e</div></td><td><span>2011-05-24 00:00:00Z</span></td><td><div class=\"dni-plaintext\">4</div></td><td>Southwest</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">10510853.8739</div></td><td><div class=\"dni-plaintext\">5366575.7098</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">dc3e9ea0-7950-4431-9428-99dbcbc33865</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr><tr><td><div class=\"dni-plaintext\">283</div></td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">250000.0000</div></td><td><div class=\"dni-plaintext\">3500.0000</div></td><td><div class=\"dni-plaintext\">0.0120</div></td><td><div class=\"dni-plaintext\">1573012.9383</div></td><td><div class=\"dni-plaintext\">1371635.3158</div></td><td><div class=\"dni-plaintext\">6bac15b2-8ffb-45a9-b6d5-040e16c2073f</div></td><td><span>2011-05-24 00:00:00Z</span></td><td><div class=\"dni-plaintext\">1</div></td><td>Northwest</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">7887186.7882</div></td><td><div class=\"dni-plaintext\">3298694.4938</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">43689a10-e30b-497f-b0de-11de20267ff7</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr><tr><td><div class=\"dni-plaintext\">284</div></td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">300000.0000</div></td><td><div class=\"dni-plaintext\">3900.0000</div></td><td><div class=\"dni-plaintext\">0.0190</div></td><td><div class=\"dni-plaintext\">1576562.1966</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">ac94ec04-a2dc-43e3-8654-dd0c546abc17</div></td><td><span>2012-09-23 00:00:00Z</span></td><td><div class=\"dni-plaintext\">1</div></td><td>Northwest</td><td>US</td><td>North America</td><td><div class=\"dni-plaintext\">7887186.7882</div></td><td><div class=\"dni-plaintext\">3298694.4938</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">0.0000</div></td><td><div class=\"dni-plaintext\">43689a10-e30b-497f-b0de-11de20267ff7</div></td><td><span>2008-04-30 00:00:00Z</span></td></tr></tbody></table>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "#!sql-adventureworks\n",
        "#!share --from value country_region_code\n",
        "\n",
        "select * from Sales.SalesPerson left join Sales.SalesTerritory on Sales.SalesPerson.TerritoryID = Sales.SalesTerritory.TerritoryID\n",
        "  where CountryRegionCode = @country_region_code"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [],
      "source": [
        "#!share --from sql-adventureworks territories\n",
        "territories"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [],
      "source": [
        "#r \"nuget: SandDance.InteractiveExtension, 1.0.45\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [],
      "source": [
        "adventureworks.SalesPeople.ExploreWithSandDance()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        },
        "vscode": {
          "languageId": "dotnet-interactive.csharp"
        }
      },
      "outputs": [],
      "source": [
        "territories"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": ".NET (C#)",
      "language": "C#",
      "name": ".net-csharp"
    },
    "language_info": {
      "file_extension": ".cs",
      "mimetype": "text/x-csharp",
      "name": "C#",
      "pygments_lexer": "csharp",
      "version": "9.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}
